from fastapi import APIRouter,Request
from .base import RouterMeta
from src.constants.resultcode import ResultCode
from src.utils.response import ApiResponse
from src.utils.logger import get_logger
from src.schemas.video_keyframe import AddVideoKeyframeRequest
from src.service.add_video_keyframe import add_video_keyframe_impl

logger = get_logger("capcut")
router = APIRouter()


@router.post("/add_keyframe",name="添加关键帧")
async def add_video_keyframe(request: Request, video_keyframe_request: AddVideoKeyframeRequest):

    try:
        draft_result = add_video_keyframe_impl(
            draft_id=video_keyframe_request.draft_id,
            track_name=video_keyframe_request.track_name,
            property_type=video_keyframe_request.property_type,
            time=video_keyframe_request.time,
            value=video_keyframe_request.value,
            property_types=video_keyframe_request.property_types,
            times=video_keyframe_request.times,
            values=video_keyframe_request.values

        )
        return ApiResponse.success(
            data=draft_result,
        )
    except Exception as e:
        logger.error(f"添加关键帧失败: {str(e)}", exc_info=True)
        return ApiResponse.error(
            result_code=ResultCode.ERROR,
            message=f"添加关键帧失败: {str(e)}",
        )

# 路由元数据配置
meta = RouterMeta(
    router=router,
    prefix="/keyframe",
    tags=["关键帧"]
)